package com.starblink.home.ui

import android.view.LayoutInflater
import android.view.ViewGroup
import com.starblink.android.basic.base.fragment.BaseTVMFragment
import com.starblink.basic.style.view.mutian.AnimationResourceModel
import com.starblink.basic.style.view.mutian.AnimationsContainer2
import com.starblink.home.databinding.*


class NavAnimFragment : BaseTVMFragment<UicoreFragmentFrameBinding, NavAnimVM>() {

    companion object {
        fun obtainFragment(): NavAnimFragment {
            return NavAnimFragment()
        }
    }

    //覆盖层的models
    private var animationsContainer: AnimationsContainer2.FramesSequenceAnimation? = null
    private val animationListener: AnimationsContainer2.AnimationListener =
        AnimationsContainer2.AnimationListener { //                Log.i(TAG, "end()  elune$id")
            //                //当前动画完组中的一个动画完成
            //                if (null != activity && !toSwitchAnother) {
            //                    (activity as UiHostActivity?).broadCast(gen("1.0", id))
            //                }
            //                if (id.startsWith("talk")) {
            //                    return
            //                }
            //                if (toSwitchAnother) {
            //                    //准备切换到下一组，先放完当前组最后一个归位动画
            //                    toSwitchAnother = false
            //                    if (animationsContainer != null && !animationsContainer.isLast()) {
            //                        //当前不是组中最后一个，执行结尾动画
            //                        animationsContainer.end()
            //                        toSwitchAnother = true
            //                    } else {
            //                        animationsContainer.stop()
            //                        models = nextModels
            //                        MtRobotLog.i(TAG, "next animation : " + models.get(0).name)
            //                        newMethod(this@FrameAnimationFragment.models, false)
            //                    }
            //                }

            animationsContainer?.start()
        }


    override fun onPause() {
        super.onPause()

    }

    private val models =
//        arrayListOf(AnimationResourceModel("frame_anim_empty", "empty_", "frame", true, 149))
        arrayListOf(AnimationResourceModel("frame_anim_camera", "img_camera_grain_00", "frame", true, 50))

    override fun initData() {
        if (animationsContainer == null) {
            animationsContainer =
                AnimationsContainer2.getInstance().createAnimation(
                    context, viewBinding.ivFrame,
                    this.models,
                )
        } else {
            animationsContainer?.reInit(this.models)
        }
        animationsContainer?.setOnAnimStopListener(animationListener)
        animationsContainer?.start()
    }

    override fun startObserve() {
        //刷新首页


    }


    override fun getViewBinding(
        inflater: LayoutInflater,
        container: ViewGroup?
    ): UicoreFragmentFrameBinding {
        return UicoreFragmentFrameBinding.inflate(inflater, container, false)
    }


}

